//
//  NetStatusHandle.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/3/29.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "NetStatusHandle.h"
#import <AFNetworking.h>

@implementation NetStatusHandle

+ (NetStatusHandle *)shareHandle
{
    static NetStatusHandle *handle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        handle = [[NetStatusHandle alloc] init];
    });
    return handle;
}

// 保存网络状态
- (void)saveNetStatus:(NSString *)status
{
    NSUserDefaults *myDefault = [NSUserDefaults standardUserDefaults];
    [myDefault setValue:status forKey:@"netStatus"];
    [myDefault synchronize];
}

// 获取网络状态
- (NSString *)getNetStatus
{
    NSUserDefaults *myDefault = [NSUserDefaults standardUserDefaults];
    return [myDefault valueForKey:@"netStatus"];
}


// 判断网络状态
- (NSInteger)judgeTheNet
{
    __block NSInteger number;
    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
    // 开启网络状态监测
    [manager startMonitoring];
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        number = status;
    }];
    return number;
}




// 自适应宽度
- (CGFloat)adjustWidth:(NSString *)tempString size:(NSInteger)size height:(NSInteger)shouldHeight
{
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:size * kAdjustParamater] forKey:NSFontAttributeName];
    CGRect frame = [tempString boundingRectWithSize:CGSizeMake(10000, shouldHeight * kAdjustParamater) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
        return frame.size.width;
}

// 自适应高度
- (CGFloat)adjustHeight:(NSString *)tempString size:(NSInteger)size width:(NSInteger)shouleWidth
{
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:size * kAdjustParamater] forKey:NSFontAttributeName];
    CGRect frame = [tempString boundingRectWithSize:CGSizeMake(shouleWidth * kAdjustParamater, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
}

@end
